package com.yhy.common.log.listener;

import cn.hutool.json.JSONUtil;
import com.yhy.common.log.event.TrackLogEvent;
import com.yhy.common.log.model.TrackLog;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author 异步监听日志事件
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class TrackLogListener {

    @Async
    @EventListener(TrackLogEvent.class)
    public void saveSysLog(TrackLogEvent event) {
        TrackLog trackLog = event.getTrackLog();
        log.debug("♦♦♦ TRACE_LOG [{}]: \n {}", trackLog.getRequestUri(), JSONUtil.toJsonPrettyStr(trackLog));
    }
}
